<?php
/**
 * Page Template
 *
 * Loaded automatically by index.php?main_page=account.<br />
 * Displays previous orders and options to change various Customer Account settings
 *
 * @package templateSystem
 * @copyright Copyright 2003-2005 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_account_default.php 4086 2006-08-07 02:06:18Z ajeh $
 * ALTER TABLE  `customers` ADD  `customers_public` BINARY( 1 ) NOT NULL DEFAULT  '0'
 */


if (isset($_POST["nick"])) {
    global $db;
    $check = "SELECT customers_nickname from " . TABLE_CUSTOMERS . " WHERE LOWER(customers_nickname)=LOWER('" . $_POST['nick'] . "')";
    $result = $db->Execute($check);
    if ($result->RecordCount() == 0) {
        $sql = "update " . TABLE_CUSTOMERS . " set customers_nickname = '" . $_POST['nick'] . "' where customers_id='" . $_SESSION['customer_id'] . "'";
        $db->Execute($sql);
        echo "<font color=red>Your nick name now is " . $_POST['nick'] . "</font>";
        sleep(1);
        header("Location: index.php?main_page=users&nick=".$_POST['nick']);
    } else {
        echo "<font color=red>This nick name (" . $_POST['nick'] . ") is not available for registration</font>";
    }
} else {
    echo TEXT_PROFILE_CREATE_PURPOSE;
    echo TEXT_PROFILE_CREATE_HOW_TO_USE;
    echo TEXT_PROFILE_CREATE_CHOOSE_NICKNAME;
echo '<form method="post"
          enctype="multipart/form-data">
        <input type="text" name="nick" id="nick" value="' . $result->fields['customers_nickname'] . '"><br>
        <input type="submit" name="Save" value="save">
            </form><br><br>';
}
?>
</div>